package com.lfd.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lfd.service.LunBoProductService;
import com.lfd.util.Result;
import com.lfd.vo.ProductVo;

@Controller
@RequestMapping("/lunbo")
public class LunBoController {

	private final Logger logger = Logger.getLogger(LunBoController.class);
	@Autowired
	private LunBoProductService lunboProductService;

	/**
	 * 显示所有
	 * 
	 * @param productVo
	 * @param page
	 * @param limit
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/list")
	public Result getlun(ProductVo productVo, @RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "limit", defaultValue = "10") Integer limit) {

		List<ProductVo> getlun = new ArrayList();
		try {
			getlun = lunboProductService.getlun(productVo, page, limit);
		} catch (Exception e) {
			logger.error("失败", e);
			return new Result("1", "失败", 100, getlun);
		}

		return new Result("0", "成功", 100, getlun);

	}

	/**
	 * 取消轮播图
	 * 
	 * @param ids
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/update")
	public Result update(@RequestParam("ids") List<Long> ids) {
		try {
			lunboProductService.update(ids);
		} catch (Exception e) {
			logger.error("异常", e);
			return new Result("1", "失败");

		}

		return new Result("0", "成功");

	}

	/**
	 * 设置轮播图
	 * 
	 * @param ids
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/szlun")
	public Result szlun(@RequestParam("ids") List<Long> ids) {
		try {
			lunboProductService.update(ids);
		} catch (Exception e) {
			logger.error("异常", e);
			return new Result("1", "失败");

		}

		return new Result("0", "成功");

	}
}
